package ledrpt

class StepWipController {

    def dynamicQueryService
    def stepWip() {
        params.SYS_QUERY_NAME='stepList'
        def stepList=dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME='stageList'
        def stageList=dynamicQueryService.queryForList(params)
        def stepWip
            if (params.wipTime == null || params.wipTime == "") {
                params.SYS_QUERY_NAME = 'stepWip'
                stepWip = dynamicQueryService.queryForList(params)
            } else {
                params.SYS_QUERY_NAME = 'stepWip7h'
                stepWip = dynamicQueryService.queryForList(params)
            }


        [stepWip:stepWip,stepList:stepList,stageList:stageList,
         step_name:params.step_name,STAGE_ID:params.STAGE_ID,wipTime:params.wipTime,part_name:params.part_name]
    }
    def exportExcel() {
        def sysQueryName

        sysQueryName = params.SYS_QUERY_NAME

        params.startNo = 1
        params.endNo = 99999999999999999
        params.startno = 1
        params.endno = 99999999999999999
        params.SYS_QUERY_NAME = sysQueryName

        def dataList = dynamicQueryService.queryForList(params)

        def tableHeadList =  []
        if(dataList.size()>0){
            tableHeadList =  dataList[0].keySet()
        }
        def stepWip

        if (params.wipTime == null || params.wipTime == "") {
            params.SYS_QUERY_NAME = 'stepWip'
            stepWip = dynamicQueryService.queryForList(params)
        } else {

            params.SYS_QUERY_NAME = 'stepWip7h'
            stepWip = dynamicQueryService.queryForList(params)
        }
        String filename = new String("${sysQueryName}.xls".getBytes("UTF-8"), "UTF-8");
        response.setContentType('application/vnd.ms-excel;charset=UTF-8')
        response.setHeader('Content-disposition', "attachment;filename=${filename};charset=UTF-8")
        response.setCharacterEncoding("UTF-8");
        render(template: "export${params.EXPORT_CONTENT_NAME}", model: [dataList: dataList,tableHeadList:tableHeadList,stepWip:stepWip])
    }
}
